<?php

namespace App\Containers\AppSection\Ban\Traits;

use App\Containers\AppSection\Ban\Models\Ban;
use App\Containers\AppSection\Project\Models\Project;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Str;

/**
 * Бан
 *
 * @property int $id Id
 * @property int $ban_id Бан
 *
 * @property Ban $ban Бан
 * @property Ban[] $bans Все баны
 */
trait HasBansModel
{
    public function bans(): hasMany
    {
        return $this->hasMany(Ban::class, $this->banKey, 'id');
    }

    public function ban(): BelongsTo
    {
        return $this->belongsTo(Ban::class, 'ban_id', 'id');
    }

    public function isNotBanned(): bool
    {
        return !$this->isBanned();
    }

    public function isBanned(): bool
    {
        return $this->getAttributeValue('ban_id') !== null;
    }
}
